'use strict';
angular.module('myApp.weather', ['ngRoute'])
    .config(['$routeProvider', function($routeProvider) {
        $routeProvider.when('/weather', {
            templateUrl: 'view/weather/weather.html',
            controller: 'WeatherCtrl'
        });
    }])
    .controller('WeatherCtrl', function($scope,$http,$rootScope) {
        //$scope.spots=[{"name":"上海","info":"上乘富饶 生态之都"},{"name":"郴州","info":"人文毓秀 五岭之冲"},{"name":"九江","info":"江山殊秀 别开洞天"},{"name":"长沙","info":"楚汉名城 屈贾之乡"},{"name":"湘西","info":"山水秀奇 飘然仙境"}];
        $http({
            method:'post',
            url:"static/json/city.json",
        }).then(function successCallback(response){
            $scope.cities=response.data;
        });
        $scope.search=function (){
            jQuery.ajax({
                type:'post',
                contentType: "application/json; charset=utf-8",
                dataType:'jsonp',
                url:'http://api.asilu.com/weather/',
                data:{'city':$scope.where},
                success:function (data){
                    $scope.city=data.city;
                    $scope.pm25=data.pm25;
                    $scope.date=data.date;
                    $scope.weather=data.weather;
                    $scope.$apply();
                    console.log(data);
                }
            })
        }
    }).directive("ngHover",function(){
        return{
            restrict:'AE',
            link:function(scope,element,attrs){
                element.bind("mouseenter mouseleave",function(event){
                    element.addClass('active');
                });
                element.bind("mouseleave",function(event){
                    element.removeClass('active');
                });
            }
        }
    });
